﻿using System;
using System.Collections.Generic;

namespace MyLib.Data {
	/// <summary>
	/// Table of user.
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class UserExtTable : System.Data.DataTable, System.Collections.Generic.IList<UserExtRow> {
		/// <summary>
		/// 
		/// </summary>
		public const int ColumnUserId = 0;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnExtId = 1;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnExtValue = 2;

		/// <summary>
		/// Create a new instance of UserExtTable.
		/// </summary>
		protected override System.Data.DataTable CreateInstance() {
			return new UserExtTable();
		}

		/// <summary>
		/// Create as new instance of UserExtRow.
		/// </summary>
		/// <param name="builder">Builder for data row.</param>
		protected override System.Data.DataRow NewRowFromBuilder(System.Data.DataRowBuilder builder) {
			return new UserExtRow(builder);
		}

		/// <summary>
		/// Count of rows.
		/// </summary>
		public int Count {
			get {
				return base.Rows.Count;
			}
		}

		/// <summary>
		/// Get row.
		/// </summary>
		/// <param name="index">Index of row.</param>
		public UserExtRow this[int index] {
			get {
				return (UserExtRow)(base.Rows[index]);
			}
			set {
				throw new System.NotImplementedException();
			}
		}

		/// <summary>
		/// Add a row.
		/// </summary>
		/// <param name="row" >Row which will be added.</param>
		public void AddRow(UserExtRow row) {
			base.Rows.Add(row);
		}

		/// <summary>
		/// Remove a row.
		/// </summary>
		/// <param name="row" >Row which will be removed.</param>
		public void RemoveRow(UserExtRow row) {
			base.Rows.Remove(row);
		}

		/// <summary>
		/// Add a new row with default values.
		/// </summary>
		public UserExtRow AddNewRow() {
			var row = base.NewRow() as UserExtRow;

			System.Diagnostics.Debug.Assert(row != null);

			base.Rows.Add(row);

			return row;
		}

		/// <summary>
		/// Type of data row.
		/// </summary>
		protected override System.Type GetRowType() {
			return typeof(UserExtRow);
		}

		#region Members of System.Collections.Generic.IEnumerable<UserExtRow>.

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public int IndexOf(UserExtRow item) {
			return base.Rows.IndexOf(item);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index" ></param>
		/// <param name="item" ></param>
		public void Insert(int index, UserExtRow item) {
			base.Rows.InsertAt(item, index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index"></param>
		public void RemoveAt(int index) {
			base.Rows.RemoveAt(index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="item" ></param>
		public void Add(UserExtRow item) {
			base.Rows.Add(item);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		bool System.Collections.Generic.ICollection<UserExtRow>.Contains(UserExtRow item) {
			throw new System.NotImplementedException();
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="keys" ></param>
		/// <returns></returns>
		public bool ContainsKey(params object[] keys) {
			System.Diagnostics.Debug.Assert(keys != null);
			System.Diagnostics.Debug.Assert(keys.Length != 0);

			return base.Rows.Contains(keys);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="array" ></param>
		/// <param name="arrayIndex" ></param>
		public void CopyTo(UserExtRow[] array, int arrayIndex) {
			base.Rows.CopyTo(array, arrayIndex);
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsReadOnly {
			get {
				return false;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		public bool Remove(UserExtRow item) {
			base.Rows.Remove(item);
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		public IEnumerator<UserExtRow> GetEnumerator() {
			var iter = base.Rows.GetEnumerator();
			while (iter.MoveNext()) {
				yield return iter.Current as UserExtRow;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
			return base.Rows.GetEnumerator();
		}

		#endregion

		/// <summary>
		/// Initialize data table.
		/// </summary>
		public UserExtTable() {
			this.TableName = "UserExtTable";
			this.BeginInit();
			var column0 = new System.Data.DataColumn("userId", typeof(string), null, System.Data.MappingType.Attribute);
			base.Columns.Add(column0);
			var column1 = new System.Data.DataColumn("extId", typeof(int), null, System.Data.MappingType.Attribute);
			base.Columns.Add(column1);
			var column2 = new System.Data.DataColumn("extValue", typeof(string), null, System.Data.MappingType.Attribute);
			column2.DefaultValue = "";
			base.Columns.Add(column2);
			this.EndInit();
		}
	} // end of UserExtTable.

	/// <summary>
	/// UserExtRow.
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class UserExtRow : System.Data.DataRow {
		/// <summary>
		/// Initialize data row.
		/// </summary>
		public UserExtRow(System.Data.DataRowBuilder builder)
			: base(builder) {
		}

		/// <summary>
		/// 
		/// </summary>
		public string UserId {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnUserId];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserExtTable[\"userId\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserExtTable.ColumnUserId];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetUserIdNull() {
			var col = base.Table.Columns[UserExtTable.ColumnUserId];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsUserIdNull {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnUserId];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public int ExtId {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnExtId];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserExtTable[\"ExtId\"] is null!");
				} else {
					return (int)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserExtTable.ColumnExtId];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetExtIdNull() {
			var col = base.Table.Columns[UserExtTable.ColumnExtId];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsExtIdNull {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnExtId];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string ExtValue {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnExtValue];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserExtTable[\"ExtValue\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserExtTable.ColumnExtValue];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetExtValueNull() {
			var col = base.Table.Columns[UserExtTable.ColumnExtValue];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsExtValueNull {
			get {
				var col = base.Table.Columns[UserExtTable.ColumnExtValue];

				return base.IsNull(col);
			}
		}
	} // end of UserExtRow.
}
